#include "crossbit/ExecutionEngine.h"

#include "crossbit/ELFMemoryImage.h"
#include "crossbit/SimpleTCache.h"
#include "crossbit/NextUseRegAllocator.h"
#include "arch/ia32/IA32Interpreter.h"
#include "arch/ia32/IA32ProcessorState.h"
#include "arch/ia32/IA32VBasicBlockBuilder.h"
#include "arch/ia32/IA32Syscall.h"
#include "arch/x86/X86Translator.h"
#include "arch/x86/X86TraceManager.h"
#include "arch/x86/X86.h"

#define TCACHE_SIZE	1024*1024*10

extern char** environ;

using namespace crossbit;

int main(int argc, char *argv[])
{
		MemoryManager*	mm = MemoryManager::getInstance();
		SimpleTCache	tcache( TCACHE_SIZE, mm );

		ELFMemoryImage 	img( (XTPStr)argv[1], (XTUint32)(argc-1), (XTPStr*)&argv[1], (XTPStr*)environ );	
		IA32ProcessorState ps;
		IA32Interpreter interp(&ps, &img);
		IA32VBasicBlockBuilder builder;
		NextUseRegAllocator alloc( 8, X86::movwMemToReg, X86::movwRegToMem, X86::movwRegToReg);
		X86Translator	tr( &ps, &alloc );
		X86TraceManager trace( mm );
		IA32Syscall sh(&ps, &img);

		ExecutionEngine ee( &img, mm, &trace, &interp, &builder, &tcache, &tr, &sh );
		ee.run();

		return 0;
}

